package com.skyworth.util;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by luwei on 17-6-23.
 */

public class CompatActivity extends Activity  implements UiCompat.CompatJBPropertyAnimationCallback{
    private View compatView = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 && needCompatJellyBean())
            UiCompat.getInstance().setCompatJBPropertyAnimationCallback(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 && needCompatJellyBean())
            UiCompat.getInstance().destroy();
    }

    public boolean needCompatJellyBean(){
        return true;
    }

    @Override
    public void forceRefresh(Rect rect) {
        ViewGroup vg = (ViewGroup) findViewById(android.R.id.content);
        if (compatView == null){
            compatView = new View(this);
            compatView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        }
        vg.removeView(compatView);
        vg.addView(compatView);
    }

}
